﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.Odbc;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class public_html_NewSite_CMSV2_ReviewsAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ReviewerMySql SQL = new ReviewerMySql();
        if (!IsPostBack)
        {
            OdbcDataReader MainReader = SQL.ExecuteReader("SELECT * FROM V2_Anmeldelse WHERE id = " + Request.QueryString["id"]);

            MainReader.Read();

            TxtID.Text = MainReader["SpilID"].ToString();
            TxtHeader.Text = MainReader["Header"].ToString();
            TxtTekst.Text = MainReader["Tekst"].ToString();
            RatingKarakter.CurrentRating = int.Parse(MainReader["Karakter"].ToString());


            lblTitel.Text = Request.QueryString["titel"];

            OdbcDataReader Reader = SQL.ExecuteReader("SELECT * FROM V2_Writters ORDER BY Navn");
            while (Reader.Read())
            {
                DropForfatter.Items.Add(new ListItem(Reader["Navn"].ToString(), Reader["ID"].ToString()));
            }

            OdbcDataReader DisReader = SQL.ExecuteReader("SELECT * FROM V2_Distributor ORDER BY Navn");
            while (DisReader.Read())
            {
                DropDis.Items.Add(new ListItem(DisReader["Navn"].ToString(), DisReader["id"].ToString()));
            }

            for (int i = 0; i < DropForfatter.Items.Count; i++)
            {
                if (DropForfatter.Items[i].Value == MainReader["Forfatter"].ToString())
                {
                    DropForfatter.Items[i].Selected = true;
                }
            }

            for (int x = 0; x < DropDis.Items.Count; x++)
            {
                if (DropDis.Items[x].Value == MainReader["Dis"].ToString())
                {
                    DropDis.Items[x].Selected = true;
                }
            }
        }
    }

    protected void BtmSave_Click(object sender, EventArgs e)
    {
        ReviewerMySql SQL = new ReviewerMySql();
        SQL.ExecuteNonQuery("UPDATE V2_Anmeldelse SET Header = '" + TxtHeader.Text + "', Tekst = '" + TxtTekst.Text + "', Karakter = " + RatingKarakter.CurrentRating.ToString() + ", Forfatter = " + DropForfatter.SelectedValue + ", Dis = " + DropDis.SelectedValue + " WHERE id = " + Request.QueryString["id"]);
        Response.Redirect("Message.aspx?MSG=Anmeldelsen blev redigeret.");
    }

    protected void BtmDelete_Click(object sender, EventArgs e)
    {
        ReviewerMySql SQL = new ReviewerMySql();
        SQL.ExecuteNonQuery("DELETE FROM V2_Anmeldelse WHERE id = " + Request.QueryString["id"]);
        Response.Redirect("Message.aspx?MSG=Anmeldelsen blev slettet.");
    }
}
